<?php

namespace App\Services;

use App\Models\Log\LogAdPostback;
use App\Models\Log\LogAdPostbackRegpay;

class AdPostbackRegpayService extends ServiceBase
{
    public function add(LogAdPostback $log, $is_post)
    {
        $item                   = new LogAdPostbackRegpay();
        $item->create_time      = time();
        $item->convert_time     = $log->convert_time;
        $item->plan_id          = $log->plan_id;
        $item->myad_group_id    = $log->myad_group_id;
        $item->myad_ad_id       = $log->myad_ad_id;
        $item->myad_creative_id = $log->myad_creative_id;
        $item->media_id         = $log->media_id;
        $item->media_docking_id = $log->media_docking_id;
        $item->game_id          = $log->game_id;
        $item->channel          = $log->channel;
        $item->media_docking_id = $log->media_docking_id;
        $item->user_id          = $log->user_id;
        $item->is_post          = $is_post;
        $item->save();

        return $item;
    }

    public function getOne($user_id)
    {
        return LogAdPostbackRegpay::where('user_id', $user_id)->first();
    }

    public function updateStatus(LogAdPostbackRegpay $item, $is_post)
    {
        $item->is_post = $is_post;
        $item->save();
    }
}
